
export const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));

export function retry(fn, retries = 5, retryDelay = 500) {
  return async (...args) => {
    for (let attempt = 1; attempt <= retries; attempt++) {
      try {
        return await fn(...args);
      } catch (error) {
        if (attempt >= retries) throw error;
        await sleep(retryDelay);
        console.error(`${fn.name} failed, retrying...`);
      }
    }
  };
}
